﻿using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Read.API.Appliaction.Commends.zmc;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Read.API.Appliaction.CommandHandlers.zmc
{
    public class QueryApparatusByIdCommandHandlers : IRequestHandler<QueryApparatusByIdCommands, ApiResult<List<Apparatus>>>
    {

        private readonly ISqlSugarClient db;

        public QueryApparatusByIdCommandHandlers(ISqlSugarClient db)
        {
            this.db = db;
        }


        /// <summary>
        /// 根据id查询数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<List<Apparatus>>> Handle(QueryApparatusByIdCommands request, CancellationToken cancellationToken)
        {

            ApiResult<List<Apparatus>> result = new ApiResult<List<Apparatus>>();
            result.Code = ApiEnums.查询成功;
            result.Msg = "查询成功";

            var list =  db.Queryable<Apparatus>().Where(it => it.ApparatusId == request.ApparatusId).ToList();

            result.Data = list;

            return result;

        }
    }
}
